import { createRouter, createWebHashHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const routes = [
  {
    path: '/index',
    name: 'index',
    component: ()=>import('../views/Index.vue'),
	children:[
		{
		  path: '/taskShow',
		  name: 'taskShow',
		  component: ()=>import('../components/taskManagement/taskShow.vue')
		},
		{
		  path: '/taskCreate',
		  name: 'taskCreate',
		  component: ()=>import('../components/taskManagement/taskCreate.vue')
		},
		{
		  path: '/taskList',
		  name: 'taskList',
		  component: ()=>import('../components/taskManagement/taskList.vue')
		},
		{
		  path: '/creatDocument',
		  name: 'creatDocument',
		  component: ()=>import('../components/documentManagement/creatDocument.vue')
		},
		{
		  path: '/manageDocument',
		  name: 'manageDocument',
		  component: ()=>import('../components/documentManagement/manageDocument.vue')
		},
		{
		  path: '/showDocument',
		  name: 'showDocument',
		  component: ()=>import('../components/documentManagement/showDocument.vue')
		},
		{
		  path: '/personalContacts',
		  name: 'personalContacts',
		  component: ()=>import('../components/contactsManagement/personalContacts.vue')
		},
		{
		  path: '/publicContacts',
		  name: 'publicContacts',
		  component: ()=>import('../components/contactsManagement/publicContacts.vue')
		},
		{
		  path: '/showNotice',
		  name: 'showNotice',
		  component: ()=>import('../components/noticeManagement/showNotice.vue')
		},
		{
		  path: '/createNotice',
		  name: 'createNotice',
		  component: ()=>import('../components/noticeManagement/createNotice.vue')
		},
		{
		  path: '/personalNotice',
		  name: 'personalNotice',
		  component: ()=>import('../components/noticeManagement/personalNotice.vue')
		},
		{
		  path: '/shortMessage',
		  name: 'shortMessage',
		  component: ()=>import('../components/instantMessaging/shortMessage.vue')
		},
		{
		  path: '/messaging',
		  name: 'messaging',
		  component: ()=>import('../components/instantMessaging/messaging.vue')
		},
		{
		  path: '/history',
		  name: 'history',
		  component: ()=>import('../components/instantMessaging/history.vue')
		},
		{
		  path: '/saveNews',
		  name: 'saveNews',
		  component: ()=>import('../components/instantMessaging/saveNews.vue')
		},
		{
		  path: '/personalInformation',
		  name: 'personalInformation',
		  component: ()=>import('../components/informationManagement/personalInformation.vue')
		},
		{
		  path: '/systemSetting',
		  name: 'systemSetting',
		  component: ()=>import('../components/informationManagement/systemSetting.vue')
		},
		{
		  path: '/password',
		  name: 'password',
		  component: ()=>import('../components/informationManagement/password.vue')
		},
		{
		 path:'/linkmanList',
		 name:'linkmanList',
		 component: ()=>import('../components/contactsManagement/publicContacts.vue')
		},
		{
		 path:'/linkmanShow',
		 name:'linkmanShow',
		 component: ()=>import('../components/contactsManagement/publicContacts.vue')
		},
		{
		 path:'/linkmanCreate',
		 name:'linkmanCreate',
		 component: ()=>import('../components/contactsManagement/publicContacts.vue')
		},
	]
  },
  {
    path: '/',
    name: 'login',
    component: () => import('../views/Login.vue')
  },
  {
	  path: '/index_admin',
	  name: 'index_admin',
	  component: ()=>import('../views/index_admin.vue'),
	  children:[
		  {
		    path: '/department',
		    name: 'department',
		    component: ()=>import('../components/adminManagement/department.vue')
		  },
		  {
		    path: '/user',
		    name: 'user',
		    component: ()=>import('../components/adminManagement/user.vue')
		  },
		  {
			  path:'/permission',
			  name:'permission',
			  component:()=>import('../components/adminManagement/permission.vue')
		  },
		  {
		  			  path:'/dictionary',
		  			  name:'dictionary',
		  			  component:()=>import('../components/adminManagement/dictionary.vue')
		  }
	  ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to,from,next)=>{
	const routList=['/index']
	let user=JSON.parse(sessionStorage.getItem("user"))
	
	if(routList.indexOf(to.path)>=0){
		if(user==null || user==''){
			route.push('/')
		}
	}
	next()
})

export default router
